package cn.com.nes.common.util;

import cn.hutool.core.util.StrUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ShenWei
 * @Date: 2024/03/08/10:18
 */
public class MyStringUtil {
    public static List<String> splitComma(String str) {
        List<String> list = new ArrayList<>();
        if (StrUtil.isNotBlank(str)) {
            if(str.contains("(")){

                str=str.replace("(", "");
                str= str.replace(")", "");
                str=str.replace("'", "");
                list = new ArrayList<>(StrUtil.splitTrim(str,","));
            }else{
                list = new ArrayList<>(StrUtil.splitTrim(str, ","));
            }
        }
        return list;
    }

    public static <T> List<T> splitComma(String str, Function<String, T> mapper) {
        List<T> list = new ArrayList<>();
        if (StrUtil.isNotBlank(str)) {
            list = StrUtil.splitTrim(str, ",")
                    .stream().map(mapper).collect(Collectors.toList());
        }
        return list;
    }
}
